'use strict';
exports.main = async (event, context) => {
  //获取中国地图数据
  const res = await uniCloud.httpclient.request('https://geo.datav.aliyun.com/areas/bound/100000_full.json', {
      method: 'GET',
      data: {
      },
      dataType: 'json',
      header: {'content-type':'application/x-www-form-urlencoded'}
    })
  //获取疫情实时数据
  const ncovcitys = await uniCloud.httpclient.request('http://api.tianapi.com/txapi/ncovcity/index', {
    method: 'POST',
    data: {
     key: 'XXXXXX',  
    },
    dataType: 'json',
    header: {'content-type':'application/x-www-form-urlencoded'}
  })
  let datas = ncovcitys.data.newslist;
  let provinces = res.data.features;
  //将疫情数据和地图数据合并在一起，用于地图渲染
  return provinces.map(province=>{
    for (var i = 0; i < datas.length; i++) {
      if(datas[i].provinceName === province.properties.name){
        return {...province,...datas[i]}
      }
    }
    return province;
  })
};